﻿using BaseUI;
using BLL;
using Model;
using System;
using System.Data;

namespace Thksoft
{
    public partial class Left : BasePage
    {
        private Sys_ModuleBLL smb = new Sys_ModuleBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string roleId = lognUser.USER_ROLEID.ToString();
                Bind(roleId);
            }
        }

        private void Bind(string roleid)
        {
            DataTable dtmg = new DataTable();
            dtmg.Columns.Add("ID", Type.GetType("System.String"));
            dtmg.Columns.Add("NAME", Type.GetType("System.String"));

            Qs_Base_Set model = new Qs_Base_SetBLL().GetModelByName("选项卡");
            string[] Card = model.Set_value.Split(';');
            for (int c = 0; c < Card.Length; c++)
            {
                DataRow newRow = dtmg.NewRow();
                newRow["ID"] = Card[c].Split(',')[0];
                newRow["NAME"] = Card[c].Split(',')[1];
                dtmg.Rows.Add(newRow);
            }

            Session["ModuleGroup"] = dtmg;

            DataTable dt = smb.GetModuleByRoleId1(roleid);
            string inntext = "<div class='menu' id='cc'>";
            if (dt != null && dt.Rows.Count > 0)
            {
                int j = 0;

                foreach (DataRow dr in dt.Rows)
                {
                    if (Convert.ToInt32(dr["MODULE_PARENTID"].ToString()) == -1)
                    {
                        j++;

                        inntext += "<div class='l1' ><img src='Images/main_left/a" + j + ".png' />&nbsp; " + dr["MODULE_NAME"].ToString() + "</div>";
                        inntext += TowBind(dr["MODULE_ID"].ToString(), roleid);//调用加载二级方法
                    }
                }
            }
            box.InnerHtml = inntext;
        }

        private string TowBind(string pid, string roleid)
        {
            string returnStr = "";
            DataTable dt = smb.findParId(roleid, pid); //获得二级数据
            if (dt != null && dt.Rows.Count > 0)
            {
                returnStr += "  <div class='slist'>";
                foreach (DataRow dr in dt.Rows)
                {
                    string str = "";
                    if (string.IsNullOrEmpty(str))
                    {
                        returnStr += "<div class='l4'>";
                    }
                    else
                    {
                        returnStr += "<div class='l2'>";
                    }
                    returnStr += "<a href='" + dr["MODULE_PATH"].ToString() + "' target='Right'>" + dr["MODULE_NAME"].ToString() + "</a></div>";
                    returnStr += str;
                }
                returnStr += " </div>";
            }
            return returnStr;
        }

        private string ThreeBind(string pid, string roleid)
        {
            string returnStr = "";
            DataTable dt = smb.findParId(roleid, pid);//获得三级数据
            if (dt != null && dt.Rows.Count > 0)
            {
                returnStr += "<ul class='sslist'>";
                foreach (DataRow dr in dt.Rows)
                {
                    returnStr += "<li class='l3'><a href='" + dr["MODULE_PATH"].ToString() + "' target='Right'>&nbsp;&nbsp;&nbsp;";
                    returnStr += dr["MODULE_NAME"].ToString();
                    returnStr += "</a></li>";
                }
                returnStr += "</ul>";
            }

            return returnStr;
        }
    }
}